package com.zztt.logmask.common.handle;

import com.zztt.logmask.common.utils.BankBinUtils;
import com.zztt.logmask.common.utils.MaskType;

/**
 * 银行卡号的掩码处理类
 */
public class BankCardMaskHandle extends AbstractRegExMaskHandle {

    /**
     * 银行卡号的正则表达式
     */
    private static final String BANK_CARD_REG_EX="((43|62|01|95|60|45)([\\d]{17}))|((62|01)([\\d]{14}))|((4)([\\d]{15}))|((60|40|)([\\d]{15}))";

    public BankCardMaskHandle(){
        super(BANK_CARD_REG_EX);
    }
    public BankCardMaskHandle(String regEx){
        super(regEx);
    }

    @Override
    protected String maskStr(String matchStr) {
        if(BankBinUtils.matchLuhn(matchStr)){
            return MaskType.BANK_CARD.mask(matchStr);
        }
        return matchStr;
    }
}
